if(Ext){
	Ext.BLANK_IMAGE_URL = '../../scripts/ext/resources/images/default/s.gif'
}
var getPrarmeterValue = function(url, paraName){
    url += '';
    if (url.indexOf('?') == -1) {
        return null;
    }
    var subUrl = url.substring(url.indexOf('?') + 1);
    var parameterPairs = subUrl.split('&');
    for (var i = 0; i < parameterPairs.length; i++) {
        var index = parameterPairs[i].indexOf(paraName + '=');
        if (index != -1) {
            var length = (paraName + '=').length;
            return parameterPairs[i].substring(index + length);
        }
    }
    return null;
}

var deleteId;
var editId;
var calculateId;
var deleteItem = function(deleteCallback, id){
    deleteId = id;
    Ext.MessageBox.confirm(message.get('message.delete.comfirm'), message.get('message.delete.tip'), deleteCallback);
}
var editItem = function(editCallback, id){
	editId = id;
	editCallback();
}
var calculate = function(calculateCallback, id){
    calculateId = id;
    Ext.MessageBox.confirm(message.get('message.delete.comfirm'), message.get('message.calculate.tip'), calculateCallback);
}

var messageTip = function(){
    var msgCt;
    
    function createBox(t, s){
        return ['<div class="msg">', 
				'<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>', 
				'<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3>', t, '</h3>', s, '</div></div></div>', 
				'<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>', 
				'</div>'].join('');
    }
    return {
        msg: function(title, format){
            if (!msgCt) {
                msgCt = Ext.DomHelper.insertFirst(document.body, {
                    id: 'msg-div'
                }, true);
            }
            msgCt.alignTo(document, 't-t');
            var s = String.format.apply(String, Array.prototype.slice.call(arguments, 1));
            var m = Ext.DomHelper.append(msgCt, {
                html: createBox(title, s)
            }, true);
            m.slideIn('t').pause(5).ghost("t", {
                remove: true
            });
        },
        
        init: function(){
			
        }
    };
}
();

Ext.onReady(messageTip.init, messageTip);

var eurMoney = function(v){
    v = (Math.round((v - 0) * 100)) / 100;
    v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
    v = String(v);
    var ps = v.split(".");
    var whole = ps[0];
    var sub = ps[1] ? "." + ps[1] : ".00";
    var r = /(\d+)(\d{3})/;
    while (r.test(whole)) {
        whole = whole.replace(r, "$1" + "," + "$2")
    }
    v = whole + sub;
    if (v.charAt(0) == "-") {
        return v.substr(1) + "&nbsp;-€&nbsp;"
    }
    return v + "&nbsp;€&nbsp;";
}

var renderStock = function(v){
    v = (Math.round((v - 0) * 100)) / 100;
    v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
    v = String(v);
    var ps = v.split(".");
    var whole = ps[0];
    var sub = ps[1] ? "." + ps[1] : ".00";
    var r = /(\d+)(\d{3})/;
    while (r.test(whole)) {
        whole = whole.replace(r, "$1" + "," + "$2")
    }
    v = whole + sub;
    //if (v.charAt(0) == "-") {
    //   return v.substr(1)
    //}
    return v;
}

var render2D = function(v){
	if(v == 0){
		return '';
	}
    v = (Math.round((v - 0) * 100)) / 100;
    v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
    v = String(v);
    var ps = v.split(".");
    var whole = ps[0];
    var sub = ps[1] ? "." + ps[1] : ".00";
    var r = /(\d+)(\d{3})/;
    while (r.test(whole)) {
        whole = whole.replace(r, "$1" + "," + "$2")
    }
    v = whole + sub;
    //if (v.charAt(0) == "-") {
    //   return v.substr(1)
    //}
    return v;
}


var render3D = function(v, p, record){
	if(v == 0){
		return '0.0';
	}
    v = (Math.round((v - 0) * 1000)) / 1000;
    v = (v == Math.floor(v)) ? v + ".000" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
    v = String(v);
    var ps = v.split(".");
    var whole = ps[0];
    var sub = ps[1] ? "." + ps[1] : ".000";
    var r = /(\d+)(\d{3})/;
    while (r.test(whole)) {
        whole = whole.replace(r, "$1" + "," + "$2")
    }
    v = whole + sub;
    //if (v.charAt(0) == "-") {
    //   return v.substr(1)
    //}
    return v;
}

var render0D = function(v, p, record){
	if(v == 0){
		return 0;
	}
    v = (Math.round((v - 0) * 1)) / 1;
    v = (v == Math.floor(v)) ? v + "" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
    v = String(v);
    var ps = v.split(".");
    var whole = ps[0];
    var sub = ps[1] ? "." + ps[1] : "";
    var r = /(\d+)(\d{3})/;
    while (r.test(whole)) {
        whole = whole.replace(r, "$1" + "," + "$2")
    }
    v = whole + sub;
    //if (v.charAt(0) == "-") {
    //   return v.substr(1)
    //}
    return v;
}

var addWorkingDay = function(inDay, interval){
	var realDay = interval;
	for(var i = 1; i <= interval; i ++){
		var day = inDay.add(Date.DAY, i).getDay();
		if(day == 6 || day == 0){
			realDay ++;
		}
	}
	var out = inDay.add(Date.DAY, realDay);
	if(out.getDay() == 6){
		out = inDay.add(Date.DAY, realDay + 2);
	}
	if(out.getDay() == 0){
		out = inDay.add(Date.DAY, realDay + 1);
	}
	return out;
}

var getValueByTagName = function(xml, tagName){
	var tags = xml.getElementsByTagName(tagName);
	for(var i = 0; i < tags.length; i ++){
		return tags[i].firstChild.data
	}
	return '';
}

var copyValue = function(src, target){
	Ext.getCmp(target).setValue(Ext.getCmp(src).getValue());
}

function renderIsYesno(value, p, record){
				if(value == '02')
					return String.format('<img src="../../images/icons/cross.png" />');
				else
					return String.format('<img src="../../images/icons/tick.png"/>');
            }

var getMeasureSpecificationItemName = function(ctStature){
	if(ctStature == '02'){
		return ['B1', 'B2', 'B3', 'B4', 'B5'];
	}else if(ctStature == '03'){
		return ['T1', 'T2', 'T3', 'T4', 'T5'];
	}else if(ctStature == '04'){
		return ['S1', 'M1', 'L1', 'S2', 'M2', 'L2'];
	}else if(ctStature == '07'){
		return ['0', '1', '2', '3', '4', '5', '6', '7'];
	}else if(ctStature == '01'){
		return ['', 'S', 'M', 'L', 'XL', 'XXL', '', ''];
	}else{
		return ['XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL', '4XL'];
	}
}

var calculator4 = function(){
	var step = parseFloat(document.getElementById('step').value);
	var size4 = parseFloat(document.getElementById('size4').value);
	if((!step || !size4) && step != 0){
		return;
	}
	var size3 = size4 - step;
	var size2 = size3 - step;
	var size1 = size2 - step;
	var size5 = size4 + step;
	var size6 = size5 + step;
	var size7 = size6 + step;
	var size8 = size7 + step;
	document.getElementById('size1').value = size1;
	document.getElementById('size2').value = size2;
	document.getElementById('size3').value = size3;
	document.getElementById('size5').value = size5;
	document.getElementById('size6').value = size6;
	document.getElementById('size7').value = size7;
	document.getElementById('size8').value = size8;
}

var calculator3 = function(){
	var step = parseFloat(document.getElementById('step').value);
	var size3 = parseFloat(document.getElementById('size3').value);
	if((!step || !size3) && step != 0){
		return;
	}
	var size2 = size3 - step;
	var size1 = size2 - step;
	var size4 = size3 + step;
	document.getElementById('size1').value = size1;
	document.getElementById('size2').value = size2;
	document.getElementById('size4').value = size4;
}

var getCalculator = function(position){
	var calNum;
	if(msRecord.data.ctStatureCode == '02' || msRecord.data.ctStatureCode == '07' || msRecord.data.ctStatureCode == '03'){
		calNum = 1;
	}else if(msRecord.data.ctStatureCode == '04'){
		calNum = 1;
	}else{
		calNum = 4;
	}
	
	if(calNum == position && position == 2){
		return '&nbsp;&nbsp;<img src="../../images/icons/calculator.png" onclick="calculator2()"/>';
	}
	
	if(calNum == position && position == 1){
		return '&nbsp;&nbsp;<img src="../../images/icons/calculator.png" onclick="calculator1()"/>';
	}
	if(calNum == position && position == 3){
		return '&nbsp;&nbsp;<img src="../../images/icons/calculator.png" onclick="calculator3()"/>';
	}
	if(calNum == position && position == 4){
		return '&nbsp;&nbsp;<img src="../../images/icons/calculator.png" onclick="calculator4()"/>';
	}
	return '';
}

var calculator1 = function(){
	var step = parseFloat(document.getElementById('step').value);
	var size1 = parseFloat(document.getElementById('size1').value);
	if((!step || !size1) && step != 0){
		return;
	}
	var size2 = size1 + step;
	var size3 = size2 + step;
	var size4 = size3 + step;
	var size5 = size4 + step;
	var size6 = size5 + step;
	var size7 = size6 + step;
	var size8 = size7 + step;
	document.getElementById('size2').value = size2;
	document.getElementById('size3').value = size3;
	document.getElementById('size4').value = size4;
	document.getElementById('size5').value = size5;
	document.getElementById('size6').value = size6;
	document.getElementById('size7').value = size7;
	document.getElementById('size8').value = size8;
}

var calculator2 = function(){
	var step = parseFloat(document.getElementById('step').value);
	var size2 = parseFloat(document.getElementById('size2').value);
	if((!step || !size4) && step != 0){
		return;
	}
	var size1 = size2 - step;
	var size3 = size2 + step;
	var size4 = size3 + step;
	var size5 = size4 + step;
	var size6 = size5 + step;
	var size7 = size6 + step;
	var size8 = size7 + step;
	document.getElementById('size1').value = size1;
	document.getElementById('size3').value = size3;
	document.getElementById('size4').value = size4;
	document.getElementById('size5').value = size5;
	document.getElementById('size6').value = size6;
	document.getElementById('size7').value = size7;
	document.getElementById('size8').value = size8;
}

var blankRecord = new Ext.data.Record();
blankRecord.data = new Array();
blankRecord.set('code', '');
blankRecord.set('description', '');

var urlArray = new Array();
var messageName = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=com.hilaver.dzmis');
urlArray[0] = new Array();
urlArray[0].className = 'com.hilaver.dzmis.basicinfo.BiFranceCustomer';
urlArray[0].url = 'basic_information/france_customer_edit.html?id={1}';
urlArray[0].menuId = '2';

urlArray[0] = new Array();
urlArray[0].className = 'com.hilaver.dzmis.basicinfo.BiFranceCustomerEshop';
urlArray[0].url = 'basic_information/france_customer_eshop_edit.html?id={1}';
urlArray[0].menuId = '2';

urlArray[1] = new Array();
urlArray[1].className = 'com.hilaver.dzmis.basicinfo.BiAccessoryButton';
urlArray[1].url = 'basic_information/accessory_button_edit.html?id={1}';
urlArray[1].menuId = '5';

urlArray[2] = new Array();
urlArray[2].className = 'com.hilaver.dzmis.basicinfo.BiAccessoryZip';
urlArray[2].url = 'basic_information/accessory_zip_edit.html?id={1}';
urlArray[2].menuId = '5';

urlArray[3] = new Array();
urlArray[3].className = 'com.hilaver.dzmis.basicinfo.BiAccessoryOthers';
urlArray[3].url = 'basic_information/accessory_others_edit.html?id={1}';
urlArray[3].menuId = '5';

urlArray[4] = new Array();
urlArray[4].className = 'com.hilaver.dzmis.basicinfo.BiArmor';
urlArray[4].url = 'basic_information/armor_edit.html?id={1}';
urlArray[4].menuId = '6';

urlArray[5] = new Array();
urlArray[5].className = 'com.hilaver.dzmis.basicinfo.BiDZColor';
urlArray[5].url = 'basic_information/dz_color_edit.html?id={1}';
urlArray[5].menuId = '30';

urlArray[6] = new Array();
urlArray[6].className = 'com.hilaver.dzmis.basicinfo.BiFactory';
urlArray[6].url = 'basic_information/factory_edit.html?id={1}';
urlArray[6].menuId = '3';

urlArray[7] = new Array();
urlArray[7].className = 'com.hilaver.dzmis.basicinfo.BiMeasureSpecification';
urlArray[7].url = 'basic_information/measure_specification_edit.html?id={1}';
urlArray[7].menuId = '4';

urlArray[27] = new Array();
urlArray[27].className = 'com.hilaver.dzmis.basicinfo.BiMeasureSpecificationItem';
urlArray[27].url = 'basic_information/measure_specification_item_edit.html?id={2}';
urlArray[27].menuId = '4';

urlArray[8] = new Array();
urlArray[8].className = 'com.hilaver.dzmis.basicinfo.BiPantoneColor';
urlArray[8].url = 'basic_information/pantone_color_edit.html?id={1}';
urlArray[8].menuId = '30';

urlArray[9] = new Array();
urlArray[9].className = 'com.hilaver.dzmis.basicinfo.BiSketch';
urlArray[9].url = 'basic_information/sketch_edit.html?id={1}';
urlArray[9].menuId = '6';

urlArray[10] = new Array();
urlArray[10].className = 'com.hilaver.dzmis.basicinfo.BiSwatch';
urlArray[10].url = 'basic_information/swatch_edit.html?id={1}';
urlArray[10].menuId = '6';

urlArray[11] = new Array();
urlArray[11].className = 'com.hilaver.dzmis.basicinfo.BiYarn';
urlArray[11].url = 'basic_information/yarn_edit.html?id={1}';
urlArray[11].menuId = '31';

urlArray[12] = new Array();
urlArray[12].className = 'com.hilaver.dzmis.order.OrderButton';
urlArray[12].url = 'order/order_button_edit.html?id={1}';
urlArray[12].menuId = '42';

urlArray[13] = new Array();
urlArray[13].className = 'com.hilaver.dzmis.order.OrderColorTest';
urlArray[13].url = 'order/order_color_test_edit.html?id={1}';
urlArray[13].menuId = '40';

urlArray[14] = new Array();
urlArray[14].className = 'com.hilaver.dzmis.order.OrderOthers';
urlArray[14].url = 'order/order_others_edit.html?id={1}';
urlArray[14].menuId = '44';

urlArray[15] = new Array();
urlArray[15].className = 'com.hilaver.dzmis.order.OrderProduct';
urlArray[15].url = 'order/order_product_edit.html?id={1}';
urlArray[15].menuId = '45';

urlArray[16] = new Array();
urlArray[16].className = 'com.hilaver.dzmis.order.OrderProductItem';
urlArray[16].url = 'order/order_product_item_edit.html?id={2}';
urlArray[16].menuId = '45';

urlArray[17] = new Array();
urlArray[17].className = 'com.hilaver.dzmis.order.OrderYarn';
urlArray[17].url = 'order/order_yarn_edit.html?id={1}';
urlArray[17].menuId = '46';

urlArray[18] = new Array();
urlArray[18].className = 'com.hilaver.dzmis.order.OrderYarnLot';
urlArray[18].url = 'order/order_yarn_lot_edit.html?id={2}';
urlArray[18].menuId = '46';

urlArray[19] = new Array();
urlArray[19].className = 'com.hilaver.dzmis.order.OrderZip';
urlArray[19].url = 'order/order_zip_edit.html?id={2}';
urlArray[19].menuId = '43';

urlArray[20] = new Array();
urlArray[20].className = 'com.hilaver.dzmis.product.ProductAccessoryButton';
urlArray[20].url = 'product/product_identification_trimming_edit.html?id={2}';
urlArray[20].menuId = '8';

urlArray[21] = new Array();
urlArray[21].className = 'com.hilaver.dzmis.product.ProductAccessoryHang';
urlArray[21].url = 'product/product_identification_trimming_edit.html?id={2}';
urlArray[21].menuId = '8';

urlArray[22] = new Array();
urlArray[22].className = 'com.hilaver.dzmis.product.ProductAccessoryOthers';
urlArray[22].url = 'product/product_identification_trimming_edit.html?id={2}';
urlArray[22].menuId = '8';

urlArray[23] = new Array();
urlArray[23].className = 'com.hilaver.dzmis.product.ProductAccessoryZip';
urlArray[23].url = 'product/product_identification_trimming_edit.html?id={2}';
urlArray[23].menuId = '8';

urlArray[24] = new Array();
urlArray[24].className = 'com.hilaver.dzmis.product.ProductIdentification';
urlArray[24].url = 'product/product_identification_edit.html?id={1}';
urlArray[24].menuId = '8';

urlArray[25] = new Array();
urlArray[25].className = 'com.hilaver.dzmis.product.ProductLaunching';
urlArray[25].url = 'product/product_launching_edit.html?id={2}';
urlArray[25].menuId = '8';

urlArray[26] = new Array();
urlArray[26].className = 'com.hilaver.dzmis.product.ProductMeasureSpecificationItem';
urlArray[26].url = 'product/product_measure_specification_item_edit.html?id={2}';
urlArray[26].menuId = '8';

urlArray[26] = new Array();
urlArray[26].className = 'com.hilaver.dzmis.product.ProductDZColor';
urlArray[26].url = 'product/product_dz_color_edit.html?id={2}';
urlArray[26].menuId = '8';

var getUrl = function(className){
	for(var i = 0; i<urlArray.length;i++){
		if(urlArray[i].className == className){
			return urlArray[i];
		}
	}
}

